package org.example.sword2offer.primary;

/**
 * @author: lynn
 * @Descript: 给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
 * Question 13
 * @date: 2021/3/8 20:05
 * @version: 1.0
 */



public class Q13_NumPower {
    public static void main(String[] args) {
        System.out.println(doPower(0,4));
    }

    private static double doPower(double d,int n){
        double sum= 1;
        if (n==0){
            return sum;
        }
        if (d==0){
            return 0.00000;
        }

        if (n>0){
            for (int i = 0; i <n ; i++) {
                sum=d*sum;
            }
        }else {
            for (int i = 0; i < -n ; i++) {
                sum=d*sum;
            }
            sum=1/sum;
        }
        return sum;
    }
}
